package com.xinxing.learning.datasource.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinxing.learning.datasource.domain.query.UserOrderInfoQuery;
import com.xinxing.learning.datasource.domain.request.UserOrderInfoRequest;
import com.xinxing.learning.datasource.domain.response.OperationResponse;
import com.xinxing.learning.datasource.domain.response.PageResponse;
import com.xinxing.learning.datasource.domain.vo.OrderInfoVO;
import com.xinxing.learning.datasource.enums.OrderCode;
import com.xinxing.learning.datasource.service.UserOrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping(value = "/user/order")
public class UserOrderController {

    @Autowired
    private UserOrderInfoService userOrderInfoService;


    /**
     * 创建订单
     *
     * @param userOrderInfoRequest 入参
     * @return OperationResponse 出参
     */
    @PostMapping("/generateOrder")
    public OperationResponse generateOrder(@RequestBody UserOrderInfoRequest userOrderInfoRequest) {
        userOrderInfoService.generateOrder(userOrderInfoRequest);
        return OperationResponse.success(OrderCode.ADD_ORDER_SUCCESS.getDesc());
    }

    /**
     * 查询订单列表
     *
     * @param userOrderInfoQuery 入参
     * @return PageResponse 出参
     */
    @GetMapping("/queryUserOrderInfoList")
    public PageResponse queryUserOrderInfoList(@RequestBody UserOrderInfoQuery userOrderInfoQuery) {
        Page<OrderInfoVO> userOrderVOPage = userOrderInfoService.queryUserOrderInfoList(userOrderInfoQuery);
        return PageResponse.success(userOrderVOPage);
    }

}
